<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="设备名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carDevchnname">
              <a-input v-model="model.carDevchnname" placeholder="请输入设备名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设备编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carDevchnid">
              <a-input v-model="model.carDevchnid" placeholder="请输入设备编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="车牌号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carNum">
              <a-input v-model="model.carNum" placeholder="请输入车牌号码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="车牌类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carNumtype">
              <a-input-number v-model="model.carNumtype" placeholder="请输入车牌类型" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="车牌颜色" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carNumcolor">
              <a-input-number v-model="model.carNumcolor" placeholder="请输入车牌颜色" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="车速" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carSpeed">
              <a-input-number v-model="model.carSpeed" placeholder="请输入车速" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="车辆类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carType">
              <a-input-number v-model="model.carType" placeholder="请输入车辆类型" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="车辆颜色" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carColor">
              <a-input-number v-model="model.carColor" placeholder="请输入车辆颜色" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="行车方向" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carDirect">
              <a-input v-model="model.carDirect" placeholder="请输入行车方向"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="车道编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carWaycode">
              <a-input v-model="model.carWaycode" placeholder="请输入车道编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="图片存放路径" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carImgurl">
              <a-input v-model="model.carImgurl" placeholder="请输入图片存放路径"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="图片存放路径" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carImg1url">
              <a-input v-model="model.carImg1url" placeholder="请输入图片存放路径"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="图片存放路径" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carImg2url">
              <a-input v-model="model.carImg2url" placeholder="请输入图片存放路径"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="图片存放路径" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carImg3url">
              <a-input v-model="model.carImg3url" placeholder="请输入图片存放路径"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="图片存放路径" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carImg4url">
              <a-input v-model="model.carImg4url" placeholder="请输入图片存放路径"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="图片存放路径" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carImg5url">
              <a-input v-model="model.carImg5url" placeholder="请输入图片存放路径"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="抓拍时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carCapdate">
              <j-date placeholder="请选择抓拍时间" v-model="model.carCapdate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="车牌图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carNumpic">
              <a-input v-model="model.carNumpic" placeholder="请输入车牌图片"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="合成图完整可访问的直接地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carCombinedpicurl">
              <a-input v-model="model.carCombinedpicurl" placeholder="请输入合成图完整可访问的直接地址"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'CarDrivingrecordForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/wdc/carDrivingrecord/add",
          edit: "/wdc/carDrivingrecord/edit",
          queryById: "/wdc/carDrivingrecord/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>